{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl8FdXdx/HPjwAiggqCFgELWlABFTEsal2qgoiiFjdcKHVfwAKPYkVra63P486jWEVBrfq4ILIoisgmVdsqGpBFpAKKShAVtQJuIOT3/HEmuTchkJvkJnOT+32/XvfFnDNz7/xuQuY3c86ZM+buiIhI9qkTdwAiIhIPJQARkSylBCAikqWUAEREspQSgIhIllICEBHJUkoAIiJZSglARCRLKQGIiGSpunEHsD3NmjXzNm3axB2GiEiNMm/evC/dvXlZ22V0AmjTpg15eXlxhyEiUqOY2cepbKcmIBGRLKUEICKSpZQARESylBKAiEiWUgIQEclSSgAiIllKCUBEpDLMtn5V0gMPwOOPpyG2MmT0fQAiItnm2WfhiivAHb74Aq6+uur2pSsAEZEM8corcN554eAPIRls2lR1+1MCEBHJAPPnwymnJA74++4LU6dC/fpVt08lABGRmK1YASecAN9+G8otW8KMGdCsWdXuVwlARCRGa9ZAr16hvR+gSROYPh322qvq911mAjCz1mY2x8yWmtkSMxsS1R9kZm+Y2WIze8HMdk56zwgzW2Fm75vZ8Un1vaO6FWZ2bdV8JRGRmmHdunDmv3JlKO+4I7z4InTsWD37T+UKYDNwlbvvD/QABplZB+Ah4Fp3PwCYDAwHiNb1BzoCvYH7zSzHzHKA+4ATgA7A2dG2IiJZ58cfQ5v/woWhnJMTOn0PO6z6Yig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SQZ3UJUwBBkbLA4HnY4ylVGbWG/g9cLK7fx93PCW5+2J3393d20R/N/lAl+j/acaqdQkg6igaDEwn/MGNd/cl8Ua1lcOBAYQz6wXRq0/cQdVAVwJPmtkioDPwPzHHUyS6MpkAzAcWE/7WYr9T1MyeBt4A9jWzfDO7ELgV6GlmywkjWG7NwBj/CjQGZkZ/Lw9kYIw1ju4EFhHJUrXuCkBERFKjBCAikqWUAEREspQSgIhIllICEBHJUkoAIiJZSglARCRLKQGIiGSp/wcrd0L5TpPx6QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 日期数据 一共15天\n",
    "date = np.linspace(1,15,15)\n",
    "# 收盘价格\n",
    "endPrice = np.array([2511.90,2538.26,2510.68,2591.66,2732.98,2701.69,2701.29,2678.67,2726.50,2681.50,2739.17,2715.07,2823.58,2864.90,2919.08])\n",
    "# 开盘价格\n",
    "beginPrice = np.array([2438.71,2500.88,2534.95,2512.52,2594.04,2743.26,2697.47,2695.24,2678.23,2722.13,2674.93,2744.13,2717.46,2832.73,2877.40])\n",
    "# print(date)\n",
    "plt.figure()\n",
    "# 用for-loop绘制15天数据\n",
    "for i in range(0,15):\n",
    "    # 柱状图\n",
    "    # 日期数据\n",
    "    dateOne = np.zeros([2])\n",
    "    dateOne[0] = i\n",
    "    dateOne[1] = i\n",
    "    # 价格数据\n",
    "    priceOne = np.zeros([2])\n",
    "    priceOne[0] = beginPrice[i]\n",
    "    priceOne[1] = endPrice[i]\n",
    "    # 若当天收盘价大于开盘价则股票上涨，用红色标注，不然为股票下跌，用绿色标注\n",
    "    if endPrice[i] > beginPrice[i]:\n",
    "        plt.plot(dateOne,priceOne,'r',lw=5)\n",
    "    else:\n",
    "        plt.plot(dateOne,priceOne,'g',lw=5)\n",
    "# 绘制相应的柱状图\n",
    "# plt.show()\n",
    "# 实现人工神经网络（ANN）\n",
    "# 为了便于计算，将日期归一化\n",
    "dateNormal = np.zeros([15,1])\n",
    "priceNormal = np.zeros([15,1])\n",
    "# i从0到14\n",
    "for i in range(0,15):\n",
    "    dateNormal[i,0] = i/14.0\n",
    "    priceNormal[i,0] = endPrice[i]/3000.0\n",
    "# 输入层：N行1列 x为日期，y为价格\n",
    "x = tf.placeholder(tf.float32,[None,1])\n",
    "y = tf.placeholder(tf.float32,[None,1])\n",
    "# 隐藏层\n",
    "# w1为1*10d的随机变量矩阵，矩阵中的值介于0,1之间\n",
    "w1 = tf.Variable(tf.random_uniform([1,10],0,1))\n",
    "b1 = tf.Variable(tf.zeros([1,10]))\n",
    "wb1 = tf.matmul(x,w1)+b1\n",
    "# 激活函数\n",
    "layer1 = tf.nn.relu(wb1)\n",
    "# 输出层\n",
    "w2 = tf.Variable(tf.random_uniform([10,1],0,1))\n",
    "b2 = tf.Variable(tf.zeros([15,1]))\n",
    "wb2 = tf.matmul(layer1,w2)+b2\n",
    "layer2 = tf.nn.relu(wb2)\n",
    "# 损失函数 (y - predict)^2 即标准差\n",
    "loss = tf.reduce_mean(tf.square(y - layer2))\n",
    "# 采用梯度下降法调整权重矩阵和偏移矩阵\n",
    "# 调整的步长\n",
    "train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)\n",
    "with tf.Session() as sess:\n",
    "    # 初始化变量\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    # 训练10000次\n",
    "    for i in range(0,10000):\n",
    "        sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})\n",
    "    # 通过训练好的模型做出预测\n",
    "    predict = sess.run(layer2,feed_dict={x:dateNormal})\n",
    "    predPrice = np.zeros([15,1])\n",
    "    for i in range(0,15):\n",
    "        # 之前已经归一化过，故要乘3000\n",
    "        predPrice[i,0] = (predict*3000)[i,0]\n",
    "    plt.plot(date,predPrice,'b',lw=3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
